package cn.cimoc.controller;

import cn.cimoc.annotation.ResponseResult;
import cn.cimoc.model.dto.inut.CartInput;
import cn.cimoc.model.dto.output.CartDTO;
import cn.cimoc.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/carts")
@ResponseResult
public class CartController extends BaseController {

    @Autowired
    CartService service;

    @PreAuthorize("hasAuthority('/cart/add')")
    @PostMapping("/add_to_cart")
    public void addToCart(Long pid, Long amount) {
        service.addToCart(pid, amount, uid, tUsername);
    }

    @PreAuthorize("hasAuthority('/cart/show')")
    @GetMapping("/")
    public CartDTO[] getCart() {
        return service.getCartList(uid);
    }

    @PreAuthorize("hasAuthority('/cart/show')")
    @GetMapping("/get_by_cids")
    public CartDTO[] getCartByCid(Long[] cids) {
        return service.getCartByCid(cids);
    }
}
